﻿@namespace MudBlazor
@inherits MudComponentBase

<div @attributes="UserAttributes" class="@TabsClassnames" style="@Style">
    <CascadingValue Value="this" IsFixed="true">
        <div class="@ToolbarClassnames">
            <div class="mud-tabs-toolbar-inner" style="@MaxHeightStyles">
                @if(HeaderPosition == TabHeaderPosition.Before && Header != null)
                {
                    <div class="mud-tabs-header mud-tabs-header-before">
                       @Header(this)
                    </div>
                }
                @if(_showScrollButtons)
                {
                    <div class="mud-tabs-scroll-button">
                        <MudIconButton Icon="@_prevIcon" Color="@ScrollIconColor" OnClick="@((e) => ScrollPrev())" Disabled="@_prevButtonDisabled" />
                    </div>
                }
                <div @ref="@_tabsContentSize" class="mud-tabs-toolbar-content">
                    <div class="@WrapperClassnames" style="@WrapperScrollStyle">
                        @foreach (MudTabPanel panel in _panels)
                        {
                            <MudTooltip Placement="@GetTooltipPlacement()" Text="@panel.ToolTip">
                                <div @ref="panel.PanelRef" class="@GetTabClass(panel)" style="@GetTabStyle(panel)" @onclick=@( e => ActivatePanel(panel, e, false) )>
                                    @if(TabPanelHeaderPosition == TabHeaderPosition.Before && TabPanelHeader != null)
                                    {
                                        <div class="mud-tabs-panel-header mud-tabs-panel-header-before">
                                            @TabPanelHeader(panel)
                                        </div>
                                    }
                                    @if (!String.IsNullOrEmpty(panel.Text) && String.IsNullOrEmpty(panel.Icon))
                                    {
                                        @((MarkupString)panel.Text)
                                    }
                                    else if (String.IsNullOrEmpty(panel.Text) && !String.IsNullOrEmpty(panel.Icon))
                                    {
                                        <MudIcon Icon="@panel.Icon" Color="@IconColor" />
                                    }
                                    else if (!String.IsNullOrEmpty(panel.Text) && !String.IsNullOrEmpty(panel.Icon))
                                    {
                                        <MudIcon Icon="@panel.Icon" Color="@IconColor" Class="mud-tab-icon-text" />
                                        @((MarkupString)panel.Text)
                                    }
                                    @if (panel.BadgeData != null || panel.BadgeDot)
                                    {
                                        <MudBadge Dot="@panel.BadgeDot" Content="@panel.BadgeData" Color="@panel.BadgeColor" Class="mud-tab-badge" />
                                    }
                                    @if(TabPanelHeaderPosition == TabHeaderPosition.After && TabPanelHeader != null)
                                    {
                                        <div class="mud-tabs-panel-header mud-tabs-panel-header-after">
                                            @TabPanelHeader(panel)
                                        </div>
                                    }
                                </div>
                            </MudTooltip>
                        }
                        @if (!HideSlider)
                        {
                            <div class="@SliderClass" style="@SliderStyle"></div>
                        }
                    </div>
                </div>
                @if(_showScrollButtons)
                {
                    <div class="mud-tabs-scroll-button">
                        <MudIconButton Icon="@_nextIcon" Color="@ScrollIconColor" OnClick="@((e) => ScrollNext())" Disabled="@_nextButtonDisabled" />
                    </div>
                }
                @if(HeaderPosition == TabHeaderPosition.After && Header != null)
                {
                    <div class="mud-tabs-header mud-tabs-header-after">
                        @Header(this)
                    </div>
                }
            </div>
        </div>
        <div class="@PanelsClassnames">
            @ChildContent
        </div>
    </CascadingValue>
</div>


